﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Circle.Web.Application.Api;
using Circle.Web.Drivers.Contract;
using System.Web.Mvc;
using Circle.Web.ViewModelsClient;
using Circle.Domain.Model;
using Circle.Manager;

namespace Circle.Web.Controllers.Api
{
    public class CommentController : BaseApiController
    {
        //[Dependency]
        private readonly ICommentDriver _commentDriver;

        public CommentController()
        {
            _commentDriver = DependencyResolver.Current.GetService<ICommentDriver>();
        }

        private void SaveComment(CommentClientModel comment)
        {
            var status = _commentDriver.Save(comment);
           
        }

        [System.Web.Http.HttpPost]
        public string Create([FromBody]string jsonModel)
        {
            var comment = ClientModel.FromJson<CommentClientModel>(jsonModel);
            SaveComment(comment);
            return comment.ToJson();
        }

        [System.Web.Http.HttpPut]
        public string Update(string key, [FromBody]string jsonModel)
        {
            var comment = ClientModel.FromJson<CommentClientModel>(jsonModel);
            SaveComment(comment);
            return comment.ToJson();
        }

        [System.Web.Http.HttpPost]
        public string CheckUploadPermissionForNewComment([FromBody]string jsonModel)
        {
            var comment = ClientModel.FromJson<CommentClientModel>(jsonModel);
            return comment.ToJson();
        }

        [System.Web.Http.HttpDelete]
        public void Delete(string key)
        {
        }
    }
}
